package org.yray.sip.factory;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.yray.sip.rtp.data.MediaContext;
import org.yray.sip.server.SipExtTable;
import org.yray.sip.server.SipServer;
import org.yray.sip.server.SipServerContext;
import org.yray.sip.server.SipServerHandler;

@Component
public class SipServerFactory {

    @Autowired
    @Qualifier("externalSipServer")
    private SipServer externalServer;

    @Autowired
    @Qualifier("internalSipServer")
    private SipServer internalSipServer;

    @Autowired
    IdRuleComponent idRuleComponent;

    public SipServer getSipServer(String id)
    {
        return idRuleComponent.isALeg(id)?externalServer:internalSipServer;
    }

    public SipServerHandler getSipServerHandler(String id)
    {
       return getSipServer(id).getSipServerHandler();
    }

    public SipServerContext getSipServerContext(String id)
    {
        return getSipServerHandler(id).getServerContext();
    }

    public MediaContext getMediaContext(String id)
    {
        return getSipServerContext(id).getMediaContext();
    }

    public SipExtTable getSipExtTable(String id)
    {
        return getSipServerContext(id).getSipExtTable();
    }
}
